package com.study.example.question;

/**
 * @Auther: likai
 * @Date: 2021/5/21 17:54
 * @Description: 指定index 将 index 前后的char数组内容进行交换.
 */
public class Question03 {

    public static void main(String[] args) {
        System.out.println(changeStr(new char[]{'a', 'l', 'i','b','a','b','a'},4));
    }

    private static char[] changeStr(char[] arr,int index) {
        if (null == arr || arr.length == 0){
            return new char[0];
        }
        int length = arr.length;
        StringBuffer temp = new StringBuffer();
        for (int i = length-1 ; i >= 0; i--) {
            if (i > index){
                temp.insert(0,arr[i]);
            } else {
                temp.insert(length-index-1,arr[i]);
            }
        }
        return temp.toString().toCharArray();
    }

}
